<%-- 
    Document   : mushroomCatalog
    Created on : 17.11.2013, 19:36:10
    Author     : palo
--%>

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" language="java" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>


<f:message var="nadpis" key="showMushrooms.title"/>

<s:layout-render name="/mainLayout.jsp" nadpis="${nadpis}">
    <s:layout-component name="body">
        <s:useActionBean beanclass="cz.muni.fi.pa165.mushroom.website.web.MushroomActionBean" var="actionBean"/>
        <shiro:hasRole name="ROLE_USER">
            <s:form beanclass="cz.muni.fi.pa165.mushroom.website.web.MushroomActionBean">
                <fieldset><legend><f:message key="showMushrooms.title"/></legend>
                    <%@include file="/protected/mushroomForm.jsp"%>
                    <s:submit name="add"><f:message key="showMushrooms.create"/></s:submit>
                    </fieldset>
            </s:form>
        </shiro:hasRole>
        <s:form beanclass="cz.muni.fi.pa165.mushroom.website.web.MushroomActionBean">
            <table class="filterByType">
                <tr>
                    <th>
                        <f:message key="filter.type"/>
                    </th>
                    <td>
                        <s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.MushroomActionBean" event="searchType">
                            <s:param name="type" value="EDIBLE"/>
                            <f:message key="EDIBLE"/>
                        </s:link> ,  
                        <s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.MushroomActionBean" event="searchType">
                            <s:param name="type" value="POISONOUS"/>
                            <f:message key="POISONOUS"/>
                        </s:link> 
                        ,
                        <s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.MushroomActionBean" event="searchType">
                            <s:param name="type" value="NOTEDIBLE"/>
                            <f:message key="NOTEDIBLE"/>
                        </s:link>  
                    </td>
                </tr>
            </table>
            <table>
                <tr>
                    <th><s:label for="b8" name="filter.name"/></th>
                    <td> <s:text id="b8" name="filter.name"/></td>
                    <td> <s:submit name="searchByName"><f:message key="showMushrooms.search"/></s:submit></td>
                    </tr>
                </table>
            <s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.MushroomActionBean" event="showMushrooms" class="cancelFilter">                       
                <f:message key="cancel.filter"/>
            </s:link> 
        </s:form>


        <h2><f:message key="showMushrooms.show"/></h2>
        <c:choose>
            <c:when test="${empty actionBean.mushrooms}">
                <p><f:message key="mushroom.list.empty"/></p>
            </c:when>
            <c:otherwise>
                <table class="basic">
                    <tr>
                        <th><f:message key="showMushrooms.name"/> </th>
                        <th><f:message key="showMushrooms.growsFrom"/></th>
                        <th><f:message key="showMushrooms.growsUntil"/></th>
                        <th><f:message key="showMushrooms.type"/></th>
                            <shiro:hasRole name="ROLE_USER">
                            <th></th>
                            <th></th>
                            </shiro:hasRole>
                    </tr>
                    <c:forEach var="mushroomDto" items="${actionBean.mushrooms}">
                        <tr>
                            <td><c:out value="${mushroomDto.name}"/></td>
                            <td><f:message key="Months.${mushroomDto.growsFrom}"/></td>
                            <td><f:message key="Months.${mushroomDto.growsUntil}"/></td>
                            <td><f:message key="${mushroomDto.type}"/></td>
                            <shiro:hasRole name="ROLE_USER">
                                <td class="button"><s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.MushroomActionBean" event="delete">
                                        <s:param name="mushroomDto.id" value="${mushroomDto.id}"/>
                                        <f:message key="tab.delete"/>
                                    </s:link>
                                </td>
                                <td class="button"><s:link beanclass="cz.muni.fi.pa165.mushroom.website.web.MushroomActionBean" event="edit">
                                        <s:param name="mushroomDto.id" value="${mushroomDto.id}"/>
                                        <f:message key="tab.edit"/>
                                    </s:link>
                                </td>
                            </shiro:hasRole>
                        </tr>
                    </c:forEach>
                </table>
            </c:otherwise>
        </c:choose>
    </s:layout-component>
</s:layout-render>